package com.atguigu.tingshu.payment.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author GQS @Date 2024/11/15/8:33 @Description
 */
/***
 * 支付服务通知其他服务的消息队列的配置
 */
@Configuration
public class PaymentRabbitConfig {

  /***
   * 听书模块的交换机
   * @return
   */
  @Bean("tingshuOrderExchange")
  public Exchange tingshuOrderExchange(){
    return ExchangeBuilder.directExchange("payment_tingshu_order_exchange").build();
  }

  /***
   * 听书模块的队列
   * @return
   */
  @Bean("tingshuOrderQueue")
  public Queue tingshuOrderQueue(){
    return QueueBuilder.durable("payment_tingshu_order_queue").build();
  }

  /**
   * 綁定
   * @param tingshuOrderExchange
   * @param tingshuOrderQueue
   * @return
   */
  @Bean
  public Binding tingshuOrderQueueBinding(@Qualifier("tingshuOrderExchange") Exchange tingshuOrderExchange,
                                          @Qualifier("tingshuOrderQueue") Queue tingshuOrderQueue){
    return BindingBuilder.bind(tingshuOrderQueue).to(tingshuOrderExchange).with("payment.order.tingshu").noargs();
  }
}
